package com.item.mall.controller;


import com.item.mall.entity.Orders;
import com.item.mall.entity.User;
import com.item.mall.service.CartService;
import com.item.mall.service.OrderDetailService;
import com.item.mall.vo.CartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张津瑞、彭家博
 * @since 2021-07-31
 */
@Controller
@RequestMapping("/orderDetail")
public class OrderDetailController {
    @Autowired
    OrderDetailService orderDetailService;
    @Autowired
    CartService cartService;

    @GetMapping("/add")
    public ModelAndView addOrderDetail(HttpServletRequest request,HttpSession session){
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.setViewName("settlement3");
        User user =(User) session.getAttribute("user");
        Orders order =(Orders)request.getAttribute("order");
        modelAndView.addObject("address",orderDetailService.addOrderDetail(user.getId(),order));
        modelAndView.addObject("order",order);
        modelAndView.addObject("pay",(String)request.getAttribute("pay"));
        modelAndView.addObject("cartList",cartService.getCartList(user.getId()));
        return modelAndView;
    }

}

